﻿using System;
using System.Collections.Generic;

namespace BibtexParser.ParserModels
{
    public class BibTexHashMap
    {
        private List<String> keys;
        private List<String> errors;
        private Dictionary<String, String> hashMap;
        private HashSet<Person> author;
        private HashSet<Person> editor;

        /**
	 * Creates and clears all the necessary files that the program needs
	 */
        public BibTexHashMap()
        {
            hashMap = new Dictionary<String, String>();
            errors = new List<String>();
            keys = new List<String>();

            author = new HashSet<Person>();
            editor = new HashSet<Person>();

            hashMap.Clear();
            errors.Clear();
            keys.Clear();
            author.Clear();
            editor.Clear();
        }

        /**
         * Returns whatever a key is in the Hashmap (or not) - yes I know that there must be a better way of doing this, 
         * but at the current moment I am more concerned about the inner workings of the regex
         * @param key
         * @return boolean
         */
        public bool containsKey(String key)
        {
            return hashMap.ContainsKey(key);
        }


        /**
         * Adds the information to the hashmap
         * @param key the key under which the value will be stored
         * @param value the value that will be stored with the key
         */
        public void put(String key, String value)
        {
            hashMap.Add(key, value);
            /* I add these keys in order to make sure that I can
             * get the keys for quick reference and testing
             * It might be removed later */
            keys.Add(key);
        }

        /**
         * Enters an error into the ArrayList that contains the errors
         * @param value the error that is to be logged
         */
        public void putError(String value)
        {
            errors.Add(value);
        }

        /**
         * Returns the error list
         * @return ArrayList<String> 
         */
        public List<String> getError()
        {
            return errors;
        }

        /**
         * Returns the the requested value from the hashmap
         * @param key the key under which the requested information is stored
         * @return String
         */
        public String get(String key)
        {
            return hashMap.ContainsKey(key) ? hashMap[key] : null;
        }

        /**
         * Returns the hashmap in which all the parsed information about the bibtex file is stored
         * @return HashMap<String, String>
         */
        public Dictionary<String, String> getHashMap()
        {
            return hashMap;
        }

        /**
         * Returns the keys that are in the hashmap
         * @return ArrayList<String>
         */
        public List<String> getKeys()
        {
            return keys;
        }

        /**
         * Sets the editors for a particular publication 
         * @param editor the editors that are to be added the publication
         */
        public void setEditor(HashSet<Person> editor)
        {
            this.editor = editor;
        }

        /**
         * Returns the editors for the publication
         * @return LinkedHashSet
         */
        public HashSet<Person> getEditor()
        {
            return this.editor;
        }

        /**
         * Sets the authors for the publication
         * @param author the authors that you want to add
         */
        public void setAuthor(HashSet<Person> author)
        {
            this.author = author;
        }

        /**
         * Returns the authors of the publication
         * @return LinkedHashSet<Person>
         */
        public HashSet<Person> getAuthor()
        {
            return author;
        }
    }
}